import unittest
import tempfile
import rpm

class TestCase(unittest.TestCase):
    def test(self):
        ''' TODO: show a full case of the "error: Unable to change root directory: Operation not permitted" bug.
        
            XXX: the rpm api needs to be able to set relocations so chroot is not called.
        '''
        tmp_root = tempfile.mkdtemp()
        ts = rpm.TransactionSet()
        ts.initDB()
        ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
        #ts.setFlags(rpm.RPMTRANS_FLAG_JUSTDB)
        mi = ts.dbMatch()
        mi.pattern('name', rpm.RPMMIRE_GLOB, 'rpm')
        headers = list(mi)
        
        # if the api was functioning properly
        self.assertTrue(len(headers) > 0)
        self.assertEquals("rpm", headers[0][rpm.RPMTAG_NAME])
        